//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Windows.Media;
using OpenLS.Drawing;

namespace OpenLS.Spreadsheet
{
    static class ColorBrushManager
    {
        [ThreadStatic]
        static Dictionary<Pair<SpreadsheetColor, ColorScheme>, Brush> _brushTable = new Dictionary<Pair<SpreadsheetColor, ColorScheme>, Brush>();
        static Dictionary<Pair<SpreadsheetColor, ColorScheme>, Brush> brushTable
        {
            get
            {
                if (_brushTable == null)
                    _brushTable = new Dictionary<Pair<SpreadsheetColor, ColorScheme>, Brush>();
                return _brushTable;
            }
        } 

        internal static Brush GetBrush(SpreadsheetColor colorReference, ColorScheme colorScheme)
        {
            if (colorReference == null)
                return null;
            Brush result;
            var key = new Pair<SpreadsheetColor, ColorScheme>(colorReference, colorScheme);
            if (!brushTable.TryGetValue(key, out result))
            {
                result = new SolidColorBrush(colorReference.GetColor(colorScheme));
                result.Freeze();
                brushTable.Add(key, result);
            }
            return result;
        }

        #region IMultiValueConverter Members

         #endregion
    }
}
